const request = require('../../utils/request.js');

/**
 * @description 酷狗音乐搜索
 * @param {string}  keyword  -  搜索关键字
 */
module.exports = (req, res) => {
  let { keyword } = req.query;
  let host = 'mobilecdn.kugou.com';
  let path = `/api/v3/search/song?format=json&keyword=${encodeURIComponent(
    keyword
  )}&page=1&pagesize=20&showtype=1`;
  let data = {};
  // false:http 请求  true:https 请求
  request
    .httpGet({ host, data, path })
    .then(function (body) {
      res.api_success(JSON.parse(body)['data']);
    })
    .catch(function (err) {
      res.api_error('服务器异常', 500);
      console.log(err);
    });
};
